package org.oaix.sm;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SmUtil;
import cn.hutool.crypto.digest.SM3;
import cn.hutool.crypto.symmetric.SM4;

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SmTest {

    public static void main(String[] args) {
        Stream.of(1,2,3,4,5,6,1).collect(Collectors.toList()).forEach(i->{
            if (i==5){
                throw new RuntimeException("test");
            }
            System.out.println(i);
        });
    }

    public static void test(){
        String data="{\"idserial\":\"123456\"}";
        String key = "DATALOOKDATALOOK";
        SM4 sm4 = SmUtil.sm4(key.getBytes());
        String encryptHex = sm4.encryptHex(data);
        String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
        System.out.println(encryptHex);
        System.out.println(decryptStr);
    }


    /**
     * 参数加密
     * @param param
     * @return
     */
    private static String encryptParam(String param,String sm4Key){
        return new SM4(sm4Key.getBytes()).encryptHex(param);
    }

    /**
     * 返回值解密
     * @param result
     * @return
     */
    private static String decryptResult(String result,String sm4Key){
        return new SM4(sm4Key.getBytes()).decryptStr(result);
    }

    /**
     * 签名
     * @param encryptParam
     * @return
     */
    private static String getSign(String encryptParam){
        return new SM3().digestHex(encryptParam);
    }
}
